package com.zzyy.study.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zzyy.study.common.PageQuery;
import com.zzyy.study.common.PageResult;
import com.zzyy.study.entities.User;
import com.zzyy.study.service.UserService;
import com.zzyy.study.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 阳
* @description 针对表【t_userv2(用户表)】的数据库操作Service实现
* @createDate 2024-06-23 16:34:35
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService
{
    @Resource
    private UserMapper userMapper;

    /**
     * PageHelper通用分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<User> selectPageHelperV1(int pageNum, int pageSize)
    {
        //开启分页
        PageHelper.startPage(pageNum, pageSize, true);

        try
        {
            List<User> users = userMapper.selectPageHelperV1();
            return PageResult.of(users);
        } finally {
            //清理分页信息
            PageHelper.clearPage();
        }
    }

    /**
     * PageHelper通用分页 + 带着条件
     * @param pageNum
     * @param pageSize
     * @param username
     * @param password
     * @return
     */
    @Override
    public PageResult<User> selectPageHelperV2(int pageNum, int pageSize, String username, String password)
    {
        //开启分页
        PageHelper.startPage(pageNum, pageSize, true);
        try
        {
            List<User> users = userMapper.selectPageHelperV2(username,password);
            return PageResult.of(users);
        } finally {
            //清理分页信息
            PageHelper.clearPage();
        }
    }

    /**
     * PageHelper通用分页+AOP,容器捞鱼V2之方法参数捞鱼
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<User> selectPageHelperAOP(int pageNum, int pageSize)
    {
        List<User> users = userMapper.selectPageHelperAOP(PageQuery.of(pageNum, pageSize, true));
        return PageResult.of(users);
    }


}




